import { DtoOmitType, classDto2Zod, formatDate } from "src/utils";
import { UserDto } from "../dto";
import { ApiProp } from "src/decorator/swagger";
import { z } from "zod";

/** 用户类型 */
export class UserVo extends DtoOmitType(UserDto, [
  'createTime',
  'updateTime',
  'roleIds'
]) {
  @ApiProp({ desc: '所属角色列表', default: ['10001', '10005'], zodType: z.array(z.string()).or(z.string())
    .transform(roleIds => (Object.prototype.toString.call(roleIds)==='[object String]') ? (<string>roleIds).split(',').filter(Boolean) : roleIds)
  })
  roleIds!: Array<string>

  @ApiProp({ desc: '创建时间', default: '2023-12-30 13:20:45', zodType: z.date().or(z.string())
    .transform(date => (Object.prototype.toString.call(date)==='[object Date]') ? formatDate(date) : date)
  })
  createTime!: string

  @ApiProp({ desc: '更新时间', default: '2023-12-30 13:20:45', zodType: z.date().or(z.string())
    .transform(date => (Object.prototype.toString.call(date)==='[object Date]') ? formatDate(date) : date)
  })
  updateTime!: string
}

export const UserVoZod = classDto2Zod(UserVo);